#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const dir = process.argv[2] ?? __dirname;

// 检查是否提供了目录名
if (!dir) {
    console.error('Error: No directory name provided.');
  } else {
    // 使用绝对路径
    const absoluteDir = path.resolve(__dirname, dir);
  
    // 检查路径是否存在
    if (!fs.existsSync(absoluteDir)) {
      console.error(`Error: Directory "${absoluteDir}" does not exist.`);
    } else {
      // 检查是否为目录
      if (fs.statSync(absoluteDir).isDirectory()) {
        try {
          // 删除目录
          fs.rmdirSync(absoluteDir);
          console.log(`Directory "${absoluteDir}" has been deleted.`);
        } catch (error) {
          console.error(`Error: Unable to delete directory "${absoluteDir}": ${error.message}`);
        }
      } else {
        console.error(`Error: "${absoluteDir}" is not a directory.`);
      }
    }
  }
